package com.cium.aqie.operator

/**
 * @Function:
 * @Author: aqie
 * @Date: 2019/8/28 11:02
 */
class Complex(var real: Double, var imaginary: Double) {
    // 定义运算符方法
    operator fun plus(other: Complex): Complex{
        return Complex(real + other.real, imaginary + other.imaginary)
    }

    operator fun plus(other: Int): Complex{
        return Complex(real + other, imaginary)
    }

    operator fun plus(other: Any): Int{
        return real.toInt()
    }

    operator fun invoke(): Double{
        // 取模
        return Math.hypot(real, imaginary)
    }

    override fun toString(): String {
        return "$real + ${imaginary}i"
    }
}